package com.inetools.gwetons.logging.shared;

import junit.framework.TestCase;

import com.inetools.gwetons.shared.logging.LogUtil;
import com.inetools.gwetons.shared.logging.LogUtilFactoryInstanceHolder;
import com.inetools.gwetons.shared.logging.LogUtilFactoryIntf;

public abstract class LogUtilAdaptedTestCase extends TestCase {
	// For logging --------------------------------------------------------------------------------
	abstract protected String getNameForLogging();
	
	private static LoggerInitializerForTest loggerInitializerForTest;
		protected static LoggerInitializerForTest getLoggerInitializerForTest() {
			return loggerInitializerForTest;
		}
		protected static void setLoggerInitializerForTest( 
				LoggerInitializerForTest loggerInitializerForTest) {
			
			LogUtilAdaptedTestCase.loggerInitializerForTest = loggerInitializerForTest;
			loggerInitializerForTest.setupLogger();
		}

	private LogUtilFactoryIntf logUtilFactoryIntf;
		/**
		 * @return logUtilFactoryIntf member field. <br />
		 * If logUtilFactoryIntf member field value is null when this method is called, then 
		 * it will be obtained via LoggerInitializerForTestGinjector. 
		 */
		protected LogUtilFactoryIntf getLogUtilFactoryIntf() {
			LoggerInitializerForTest loggerInitializerForTest
			= LogUtilAdaptedTestCase.getLoggerInitializerForTest();
				if ( loggerInitializerForTest == null) {
					loggerInitializerForTest 
					= LoggerInitializerForTestAccessor.getLoggerInitializerForTestInstance();
						LogUtilAdaptedTestCase.setLoggerInitializerForTest( loggerInitializerForTest);
						loggerInitializerForTest.setupLogger();
				}
			
			if ( logUtilFactoryIntf == null) {
				setLogUtilFactoryIntf( 
						LogUtilFactoryInstanceHolder.getLogutilfactory()
						);
			}
			
			return logUtilFactoryIntf;
		}
		protected void setLogUtilFactoryIntf( LogUtilFactoryIntf logUtilFactoryIntf) {
			
			this.logUtilFactoryIntf = logUtilFactoryIntf;
			setLogUtil( null);
		}

	private LogUtil logUtil;
		/**
		 * @return logUtil member field. <br />
		 * If logUtil member field value is null when this method is called, then it will be 
		 * obtained via getLogUtil method of logUtilFactoryIntf member field. At that time, if 
		 * logUtilFactoryIntf member field value is null, then LogUtilFactory.FacoryInstance 
		 * will be set to logUtilFactoryIntf member field. 
		 */
		protected LogUtil getLogUtil() {
			if ( logUtil == null) {
				setLogUtil( 
						getLogUtilFactoryIntf().getLogUtil( getNameForLogging())
						);
			}
			return logUtil;
		}
		protected void setLogUtil( LogUtil logUtil) {
			this.logUtil = logUtil;
		}
	// --------------------------------------------------------------------------------------------
}
